/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ncsu.csc573.project1.util;

/**
 *
 * @author svpendse1
 */
public class Constants {

    public static final int kPortScanLow = 1024;
    public static final int kPortScanHigh = 65535;
    public static final int kPortNumber = 7734;
    public static String kHostName = "127.0.0.1";
    public static final String kVersion = "P2P-CI/1.0";
    public static final String kContentType = "text/plain";
    public static final int kEndOfMessage = -1;
    public static enum PPMethod {
        GET ("GET"),
        CLOSE ("CLOSE");

        String name;
        
        PPMethod(String name) {
            this.name = name;    
        }
        
        String getName() {
            return name;
        }
        
        static PPMethod constructMethodFromName(String name) {
            if (name.equals("GET")) {
                return PPMethod.GET;
            } else if (name.equals("CLOSE")) {
                return PPMethod.CLOSE;
            }
            return null;
        }
    }

    public static enum PSMethod {
        ADD ("ADD"),
        LOOKUP ("LOOKUP"),
        LIST ("LIST"),
        CLOSE ("CLOSE");
        
        String name;
        PSMethod(String name) {
            this.name = name;
        }

        String getName() {
            return name;
        }

        static PSMethod constructMethodFromName(String name) {
            if (name.equals("ADD")) {
                return PSMethod.ADD;
            } else if (name.equals("LOOKUP")) {
                return PSMethod.LOOKUP;
            } else if (name.equals("LIST")) {
                return PSMethod.LIST;
            } else if (name.equals("CLOSE")) {
                return PSMethod.CLOSE;
            }
            return null;
        }
    }
    
    public static enum Status {
        OK ("OK", 200), 
        BAD_REQUEST ("Bad Request", 400), 
        NOT_FOUND ("Not Found", 404),
        P2P_CI_VERSION_NOT_SUPPORTED ("P2P-CI Version Not Supported", 505);

        String phrase;
        int code;
        
        Status(String phrase, int code) {
            this.phrase = phrase;
            this.code = code;
        }

        String getPhrase() {
            return phrase;
        }

        int getCode() {
            return code;
        }

        static Status constructFromPhraseAndCode(String phrase, int code) {
            //System.out.println(phrase + " " + code);
            if (phrase.equals("OK") && code == 200) {
                return Status.OK;
            } else if (phrase.equals("Bad Request") && code == 400) {
                return Status.BAD_REQUEST;
            } else if (phrase.equals("Not Found") && code == 404) {
                return Status.NOT_FOUND;
            } else if (phrase.equals("P2P-CI Version Not Supported") && code == 505) {
                return Status.P2P_CI_VERSION_NOT_SUPPORTED;
            }
            return null;
        }
    };
}

